package com.xy.strategy;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/21 21:00
 * @description
 */
public class ComparatorTest {
    public static void main(String[] args) {
        Integer[] data1 = {1, 6, 3, 8, 2, 9};
        Comparator<Integer> comparator = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 > o2 ? -1 : 1;
            }
        };
        Arrays.sort(data1, comparator);

        System.out.println(Arrays.toString(data1));
        Integer[] data2 = {1, 6, -1, 3, 8, 2, 9};
        Arrays.sort(data2, (o1, o2) -> o1 - o2);

        System.out.println(Arrays.toString(data2));
    }
}
